package com.isay.frameworklib.utils;

import android.content.Context;

import com.isay.frameworklib.R;

/**
 * 点击事件工具类
 * Created by cywu4 on 2018/1/4.
 */

public class ClickUtils {

    private static final int CLICK_INTERVAL_MS = 300;

    private static long sLastClickTimeMs;

    private static long sLastDoubleClickTimeMs;


    /**
     * 判断用户是否是快速点击
     *
     * @return 是否是快速点击
     */
    public static boolean isFastClick() {
        long curTime = System.currentTimeMillis();
        if (curTime - sLastClickTimeMs > CLICK_INTERVAL_MS || curTime < sLastClickTimeMs) {
            sLastClickTimeMs = curTime;
            return false;
        }
        return true;
    }

    /**
     * 判断用户是否是快速点击
     *
     * @return 是否是快速点击
     */
    public static boolean isFastClick(long interval) {
        if (interval < 0) {
            interval = 2000;
        }
        long curTime = System.currentTimeMillis();
        if (curTime - sLastDoubleClickTimeMs < interval || curTime < sLastDoubleClickTimeMs) {
            sLastDoubleClickTimeMs = curTime;
            return true;
        } else {
            sLastDoubleClickTimeMs = curTime;
            return false;
        }
    }




}
